//
//  MeViewController.m
//  Auditory
//
//  Created by 寒竹子 on 15/4/28.
//  Copyright (c) 2015年 寒竹子. All rights reserved.
//

#import "MeViewController.h"
#import "RootNavigationController.h"
#import "ScanViewController.h"

@interface MeViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, strong) NSArray * dataArray;
@property (nonatomic, strong) UITableView * tableView;

@end

@implementation MeViewController

- (instancetype)init
{
    if (self = [super init]) {
        _dataArray = @[@[@"我的下载", @"我的收藏", @"扫 一 扫"], @[@"分     享", @"设     置", @"关     于"]];
    }
    
    return self;
}

- (UITableView *)tableView
{
    if (_tableView == nil) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 64.0f) style:UITableViewStyleGrouped];
        
        _tableView.delegate = self;
        _tableView.dataSource = self;
        
        _tableView.showsHorizontalScrollIndicator = NO;
        _tableView.showsVerticalScrollIndicator = NO;
        
        _tableView.tableFooterView = [[UIView alloc] init];
    }
    
    return _tableView;
}

/**
 * @brief  初始化UI
 *
 * @param
 * @return
 */
- (void)setupUI
{
    self.view.backgroundColor = RGB(248, 248, 248, 1.0f);
    
    [self.view addSubview:self.tableView];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)]) {
        [self setEdgesForExtendedLayout:UIRectEdgeNone];
    }
    
    [self setupUI];
}

#pragma mark - UITableViewDelegate

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [_dataArray[section] count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * cellId = @"cellID";
    
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
    }
    
    cell.textLabel.font = TextFont(17.0f);
    cell.textLabel.textColor = RGB(10, 10, 10, 1.0f);
    cell.textLabel.text = _dataArray[indexPath.section][indexPath.row];
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if (indexPath.section == 0) {
        if (indexPath.row == 2) {
            ScanViewController * scanVc = [[ScanViewController alloc] init];
            [self.rootNav pushViewController:scanVc animated:YES];
        }
    }else {
        
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50.0f;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
